A jQuery plugin for using FontAwesome icons as custom CSS cursors. Works in Chrome and FireFox.
Try hovering over this!
Now also supports using an alternative icon font!
In your terminal:
In your web page:
If you plan on using jquery-awesome-cursor
with a different icon font, you can skip the FontAwesome dependency:
In your terminal:
In your web page:
IMPORTANT: As of v0.3.0
, FontAwesome is considered an optional dependency. Therefore, you must install it yourself!
The download links below are for the latest versions of the code, which may be unstable.
To view the latest stable release, and previous releases, please visit https://github.com/jwarby/jquery-awesome-cursor/releases .
Download just the script:
jquery.awesome-cursor.min.js (production) jquery.awesome-cursor.js (development)Or download an archive of the latest code:
.zip .tar.gzThen, in your web page:
You could also use RawGit's CDN:
To set a cursor on an element, just call $('<selector>').awesomeCursor('<icon name>');
For example, to use the pencil icon
as the <body>
element's cursor, do the following:
Cursors also support a number of options, which are detailed in the next section.
Options are set by passing an object as the second parameter to awesomeCursor()
:
You can reset the cursor to it's previous icon using jQuery's css
function:
The cursor attributes can be configured using the options listed below.
type: String
The first parameter to awesomeCursor
is the icon name.
type: String
The color of a cursor can be changed by setting the color
option to any valid CSS color string:
type: Number
The size of the cursor can be changed by setting the size
option.
Note: cursor sizes can only be defined in pixels, as the cursor hotspot CSS syntax only supports pixels
type: String or Array
The hotspot location of the cursor can be defined using the hotspot
option. This allows you to configure the point that the actual click will emanate from.
The hotspot can be configured in two different ways: using an array containing the [x, y]
coordinates (in pixels) of the hotspot, or by using a descriptive string
.
If you're using an array of coordinates, the values will be clamped between 0 and the size of the cursor minus 1. This is because the browser will default to 0, 0
for coordinates beyond the
boundaries of the cursor.
The strings 'bottom', 'top', 'left', 'right' and 'center' are recognised. These values can be combined by space-separating them; some examples are shown below:
type: String
The cursor can be flipped horizontally, vertically, or in both directions by setting the flip
option.
flip
can be one of:
To disable flipping, set flip
to any falsy value (false
, null
, ''
, etc.). All other
values will result in an error being thrown.
type: Number
The cursor can be rotated any number of degrees using the rotate
option.
type: String
An outline can be applied to a cursor by setting the outline
option to any valid CSS color string.
The default values for all options are exposed by $.fn.awesomeCursor.defaults
. This means you can easily override default options:
You may want to use an icon font other than FontAwesome for your cursors - this can be achieved using the font
option (as of
v0.1.0).
The font
option is an object, containing the font family
and cssClass
. The example below demonstrates how to use typicons
as the icon font:
family
option is the name of the font icon's family. For FontAwesome, it's 'FontAwesome'; for typicons it's 'typicons'cssClass
option is the format of the replacement font icon's CSS classes, where %s
is the name of the icon passed as the first parameter to awesomeCursor
. You can also
use a function instead of a string - the function receives the icon name as it's only parameter, and is expected to return the CSS class name for the icon, e.g.
You can set an alternative font as the default in the same way you would override other defaults:
Hover your cursor over the boxes to see the example cursors